﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using GMS.Model;
using System.Collections.Generic;//for list
//using GMS.Utils;
using System.Text.RegularExpressions;
//using GMS.Utils.ServiceContext;
//using GMS.BLL;
//using DL.Web.CommonPage;

public partial class System_SysParameters_Default : System.Web.UI.Page
{
    //public ComOperate CDO = new ComOperate();
    //ManageControls MCls = new ManageControls();
    //DBAndBizTableConverter BizTab = new DBAndBizTableConverter();

    public string tabBizType = string.Empty;
    public DataSet tableDs = new DataSet();//数据集
    private const string tablecode = "TAB_SYSFUNMODULE";
    int level = 1;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //tableCode = tablecode;
            //tabDBCode = tableCode;
            //tabBizType = "";

            //initWhere = "TABSYSID in (" + OP.UserModuleRight.Trim(',') + ")";
            //tableDs = CDO.GetComData(tabDBCode, initWhere + " and fathermoduleid is null", 0, 0, "order by moduleseq",null);
            //if (tableDs == null || tableDs.Tables.Count == 0)
            //    return;
            //LoadAll(tableDs);
        }
        else
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "将控件补上字符", "<script>FillControl();</script>");
        }
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        //isRestored = false;
    }

    public void LoadAll(DataSet ds)
    {
        //LoadData(ds, 0, int.MaxValue);
    }

    //特别注意：front：表示从查出来的ds.Tables[0]里面的第front行开始，end行结束，而不是数据库里面的第几行开始和结束
    public void LoadData(DataSet ds, int front, int end)
    {
        //try
        //{
        //    if (ds == null || ds.Tables.Count == 0) //条件查询等要调用的LoadData（），必须判读
        //        return;

        //    DataTable dt = ds.Tables[0];
        //    tab_content.InnerHtml = "";
            
        //    CDO.Init(tableCode);
        //    CDO.SetListShowColAdnKeyDic();
        //    Dictionary<string, TabColumns> tabColumns = CDO.TabListShowedColDict;
        //    Dictionary<string, string> keys = CDO.TabKeyDict;

        //    string tKeys = "";
        //    string tabDBCode = string.Empty;

        //    Dictionary<string, string>.Enumerator de = keys.GetEnumerator();
        //    //获取主键
        //    for (; de.MoveNext(); )
        //    {
        //        tKeys += de.Current.Key + ",";
        //    }
        //    string[] arr = tKeys.Substring(0, tKeys.Length - 1).Split(',');
        //    //要显示的列
        //    int showColNum = 0;

        //    string columnsString = "";

        //    Dictionary<string, CheckInfoWithCon> checkCon = new Dictionary<string, CheckInfoWithCon>();
        //    if (dt.Rows.Count == 0)
        //    {
        //        tab_content.InnerHtml += "<td colspan='" + Convert.ToString(dt.Columns.Count) + "'>null</td>";
        //        return;
        //    }
        //    StringBuilder tbodyStr = new StringBuilder();
        //    string[] colHtmls = TableUtility.ToColumnHtml(tabColumns, dt);
           

        //    columnsString = ",";
        //    for (int i = 0; i < dt.Columns.Count; i++)
        //    {
        //        if (tabColumns.ContainsKey(dt.Columns[i].Caption.ToUpper()))
        //        {
        //            if (tabColumns[dt.Columns[i].Caption].COLSHOWED == 1)
        //            {
        //                columnsString += dt.Columns[i].Caption.ToUpper() + ",";
        //                break;
        //            }
        //        }
        //    }
            

        //    string[] arrColumns = columnsString.Split(',');
        //    //设置每列显示字符串最大长度
        //    int colMaxSize;
        //    colMaxSize = int.TryParse(SysSettings.GetTDMaxLength(),out colMaxSize) ? colMaxSize : 20;
        //    string fatherid = "0";
        //    ShowDataRow(arr, front, end, arrColumns, colMaxSize, dt, ref tbodyStr, fatherid, true, 0);

        //    tab_content.InnerHtml += tbodyStr.ToString();
        //}
        //catch (Exception ex)
        //{
        //    this.Page.RegisterClientScriptBlock("toAlert", "<script>alert('表格数据读取出错:" + comUse.SafeAlertMsg(ex.Message) + "');</script>");
        //}
    }

    private void ShowDataRow(string[] arr, int front, int end, string[] arrColumns, int colMaxSize, DataTable dt, ref StringBuilder tbodyStr, string fatherid, bool display, int padSpace)
    {
        //for (int i = front; (i < dt.Rows.Count) && (i < end); i++)
        //{
        //    string dataId = "";
        //    string id = "";
        //    string proteyValue = dt.Rows[i]["MODULENAME"].ToString(); ;
        //    bool showExpand = false;

        //    string firstLevel = "";
        //    string startLi = "";
        //    string endLi = "";
        //    string ListStyle = "";
        //    string hidde = "";


        //    if (level == 1)
        //    {
        //        firstLevel = "class='FirstLevel'";
        //    }
        //    else
        //    {
        //        firstLevel = "";
        //        hidde = "display:none;";
        //    }

        //    for (int z = 0; z < arr.Length; z++)
        //    {
        //        dataId += arr[z] + "-" + dt.Rows[i][arr[z]].ToString() + ";";
        //        id = dt.Rows[i][arr[z]].ToString();
        //    }
        //    DataSet childTableDs = CDO.GetComData(tabDBCode, initWhere + " and fathermoduleid='" + id + "'", 0, 0, "order by moduleseq", null);


        //    if (childTableDs != null && childTableDs.Tables[0].Rows.Count > 0 && dt.Rows[i]["ISUNFOLD"].ToString() == "0")
        //    {
        //        showExpand = true;
        //    }

        //    dataId = dataId.TrimEnd(';');
        //    if (display)
        //        tbodyStr.Append("<tr id='child_" + fatherid + "_" + id + "' style='display:block' >");
        //    else
        //    {
        //        tbodyStr.Append("<tr id='child_" + fatherid + "_" + id + "' style='display:none' >");
        //    }

        //    string img = "<img class=\"imgStyle\" id=\"img_" + fatherid + "_" + id + "\" ";
        //    string showImg = "";
        //    if (showExpand || level == 1)
        //    {
        //        if (level == 1)
        //        {
        //            if (showExpand)
        //            {
        //                img += " src=\"../images/Main/Whitecollapse.png\" onclick=\"ExpandChildren(this,'child_" + fatherid + "_" + id + "'," + level + ")\" title='展开'  />";
        //            }
        //            else
        //            {
        //                img += " src=\"../images/Main/Unexpand.png\" title='不能展开'  />";
        //            }
        //        }
        //        else if (showExpand)
        //        {
        //            img += " src=\"../images/Main/Whitecollapse.png\" onclick=\"ExpandChildren(this,'child_" + fatherid + "_" + id + "'," + level + ")\" title='展开'  />";
        //        }
        //    }
        //    else
        //    {
        //        //img += " src=\"../../images/img/pointD.png\" title='不能展开'  />";
        //        img = "";
        //        startLi = "<li style=\"padding-left:2px\">";
        //        endLi = "</li>";
        //    }
        //    tbodyStr.Append("\r\n");

        //    string colValue = dt.Rows[i]["MODULENAME"].ToString();

        //    tbodyStr.Append("<td nowrap style=\" text-align:left;padding-left:" + padSpace + "px;\" title='" + "" + "'" + firstLevel + ">");
        //    tbodyStr.Append("\r\n");
        //    tbodyStr.Append(img);
        //    string href = "";
        //    if (dt.Rows[i]["URL"].ToString().Replace("~", "").Trim() != "")
        //    {
        //        href = "href=\"" + dt.Rows[i]["URL"].ToString().Replace("~", "..") +"\"";
        //    }
        //    tbodyStr.Append("<div style=\"padding-top:3px\"><a " + href + " onclick=\"imgExpand('img_" + fatherid + "_" + id + "',this)\" target='ContFrame' style=\"\" onmouseover=\"pos1(this)\" onmouseout=\"hidden(this)\" title='" + dt.Rows[i]["ROUTINE"].ToString() + "' >");// ROUTINE   
        //    tbodyStr.Append(startLi + colValue + endLi);
        //    tbodyStr.Append("</a></div>");
        //    tbodyStr.Append("\r\n");
        //    tbodyStr.Append("</td>");
        //    tbodyStr.Append("\r\n");

        //    tbodyStr.Append("</tr>");

        //    //添加子类型行

        //    if (showExpand)
        //    {
        //        level++;
        //        DataTable childDT = childTableDs.Tables[0];
        //        int padSpace2 = padSpace + 20;
        //        ShowDataRow(arr, 0, childDT.Rows.Count, arrColumns, colMaxSize, childDT, ref tbodyStr, fatherid + "_" + id, false, padSpace2);

        //        level--;
        //    }
        //    tbodyStr.Append("\r\n");
        //}
    }
 
}
